﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint;

namespace SPDesigner.Policy
{
    


    public class SPDAdminJob:SPJobDefinition
    {
            public SPDAdminJob () : base() { }

            public SPDAdminJob(SPWebApplication webApp)
            : base(Globals.JobName, webApp, null, SPJobLockType.Job) 
             {
              this.Title = Globals.JobName;
            }

            public SPDAdminJob(SPWebApplication webApp,string jobname)
                : base(jobname, webApp, null, SPJobLockType.Job)
            {
                this.Title = jobname;
            }

            public override void Execute(Guid targetInstanceId)
            {
                SPDAdminJobSettings settings = this.WebApplication.GetChild<SPDAdminJobSettings>(Globals.SettingsID);
                foreach (SPSite site in this.WebApplication.Sites)
                {
                    if (settings.SiteCollectionsEnabled.ContainsKey(site.ID))
                        SPDAdminLogic.SetSPSiteSPD(site, settings.SiteCollectionsEnabled[site.ID]);
                     site.Dispose();
                }


            }

      


    }
}
